//
//  FRTimerManager.m
//  物理仿真
//
//  Created by Annie on 2020/5/27.
//  Copyright © 2020 Annie. All rights reserved.
//

#import "FRTimerManager.h"

@interface FRTimerManager ()

@property (nonatomic, strong) NSTimer *timer;

@end


@implementation FRTimerManager


+ (instancetype)manager{
    
    static FRTimerManager *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [FRTimerManager new];
    });
    return instance;
}





- (void)startTimer{
    if (_timer) {
        [self.timer invalidate];
    }
    [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
}




- (NSTimer *)timer{
    if (!_timer) {
        NSTimer *timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(count:) userInfo:nil repeats:YES];
        _timer = timer;
    }
    return _timer;
}

- (void)count:(NSTimer *)sender{
    
    [[NSNotificationCenter defaultCenter] postNotificationName:kFRTimerCountNotification object:sender];
    
}


@end
